package com.cratos.xxgram.platf.friend;

import com.cratos.xxgram.platf.base.BaseEntity;
import com.cratos.xxgram.platf.base.UserInfo;
import javax.persistence.*;
import org.redkale.convert.json.*;
import org.redkale.util.*;
/**
 *
 * @author zhangjx
 */
@Table(comment = "用户表")
//@Cacheable
public class FriendShip extends BaseEntity {
    
    private static final Reproduce<FriendShipHis, FriendShip> reproduce = Reproduce.create(FriendShipHis.class, FriendShip.class);
    
    @Comment("好友 昵称长度最大值")
    public static final short FRIENDNAME_MAXLEN = 20;
    
    @Comment("黑名单好友")
    public static final short RELATION_SHIP_BLACKLIST = 10;
    
    @Comment("普通好友")
    public static final short RELATION_SHIP_NORMAL = 20;
       
    @Comment("陌生人")
    public static final short RELATION_SHIP_STRANGER = 30;
    
    @Comment(" 好友对自己正常显示在线状态")
    public static final short REL_STATUS_NORMAL = 10;
    
    @Comment(" 好友对自己隐身了")
    public static final short REL_STATUS_STEALTH = 20;
    
    @Comment("用户在线状态")
    public static final short ONLINE_STATUS_ONLINE = 20;
    
    @Comment("用户离线状态")
    public static final short ONLINE_STATUS_OFFLINE = 10;
    
    @Comment("手机搜索添加")
    public static final short REQ_BY_MOBILE = 10;
    
    @Comment("二维码扫描添加")
    public static final short REQ_BY_SCAN = 20;
    
    @Comment("ID添加")
    public static final short REQ_BY_ID = 30;
    
    
    @Id
    @Column(length = 64, comment = "userid+“-”+friendid ")
    private String friendshipid = "";

    @Column(comment = "用户ID")
    private int userid;

    @Column(comment = "好友ID")
    private int friendid;

    @Column(length = 64, comment = "好友的备注名")
    private String friendname = "";

    @Deprecated(since = "下个版本， 好友备注 用 friendname 已代替")
    @Column(length = 255, comment = "备注信息")
    private String remark = "";

    @Column(comment = "加好友方式; 10:手机搜索; 20:扫二维码; 30:ID添加;")
    private short invitetype;

    @Column(updatable = false, comment = "加好友时间")
    private long createtime;

    @Transient
    private UserInfo friend;
    
    @Column(comment = "好友列表 关系 10 被加入了黑名单 20 正常好友 30 陌生人")
    private short relationship = RELATION_SHIP_NORMAL;
    
    @Column(comment = "在线状态 10 离线 20 在线")
    private short onlinestatus = ONLINE_STATUS_OFFLINE;
    
    @Column(comment = "好友对自己的状态 10 正常 20 隐身")
    private short relstatus = REL_STATUS_NORMAL;
 
    @Column(comment = "第1位表示 消息免打扰 "
                    + " 第2位表示 阅后即焚"
                    + " 第3位表示 添加到了黑名单 ")
    protected long syssetting = 0;
       
    @Column(comment = "聊天背景图url")
    private String chatbackground = "";
    
    @Transient
    private  boolean isfriend = true;

    public static final int NO_SECRET = 10;
    
    public static final int HAVE_SECRET = 20;
    
    @Comment("用户密信")
    @Transient
    private String secret;
    
    @Comment("是否存在密信 10 没有 设置 20 已经设置密信")
    @Transient
    private int secretstatus = NO_SECRET;
    
    
    public String getSecret() {
		return secret;
	}

	public void setSecret(String secret) {
		this.secret = secret;
	}

	public int getSecretstatus() {
		return secretstatus;
	}

	public void setSecretstatus(int secretstatus) {
		this.secretstatus = secretstatus;
	}

	public String getChatbackground() {
        return chatbackground;
    }

    public void setChatbackground(String chatbackground) {
        this.chatbackground = chatbackground;
    }

    public short getOnlinestatus() {
        return onlinestatus;
    }

    public void setOnlinestatus(short onlinestatus) {
        this.onlinestatus = onlinestatus;
    }

    public short getRelstatus() {
        return relstatus;
    }

    public void setRelstatus(short relstatus) {
        this.relstatus = relstatus;
    }
    
    public short getRelationship() {
        return relationship;
    }

    public void setRelationship(short relationship) {
        this.relationship = relationship;
    }
    
    public boolean isIsfriend() {
        return isfriend;
    }

    public void setIsfriend(boolean isfriend) {
        this.isfriend = isfriend;
    }
    
    public UserInfo getFriend() {
        return friend;
    }

    public void setFriend(UserInfo friend) {
        this.friend = friend;
    }

    public void setFriendshipid(String friendshipid) {
        this.friendshipid = friendshipid;
    }

    public String getFriendshipid() {
        return this.friendshipid;
    }

    public void setUserid(int userid) {
        this.userid = userid;
    }

    public int getUserid() {
        return this.userid;
    }

    public void setFriendid(int friendid) {
        this.friendid = friendid;
    }

    public int getFriendid() {
        return this.friendid;
    }

    public void setFriendname(String friendname) {
        this.friendname = friendname;
    }

    public String getFriendname() {
        return this.friendname;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getRemark() {
        return this.remark;
    }

    public void setInvitetype(short invitetype) {
        this.invitetype = invitetype;
    }

    public short getInvitetype() {
        return this.invitetype;
    }

    public void setCreatetime(long createtime) {
        this.createtime = createtime;
    }

    public long getCreatetime() {
        return this.createtime;
    }

    @Override
    public String toString() {
        return JsonConvert.root().convertTo(this);
    }

    public long getSyssetting() {
        return syssetting;
    }

    public void setSyssetting(long syssetting) {
        this.syssetting = syssetting;
    }
    
    @Comment("历史数据")
    public FriendShipHis createRandomHis() {
        FriendShipHis his = reproduce.apply(new FriendShipHis(), this);
        his.setDeletetime(System.currentTimeMillis());
        his.setSeqid(Utility.format36time(his.getCreatetime()) + "-" + Utility.uuid());
        return his;
    }
}
